// subpackage/collection/collection.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    headPortraitList:[],
    headPortraitshorthandList:[]
  },

  saveheadPortraitToStorage(headPortraitList) {
    // uni.setStorageSync('cart', JSON.stringify(state.cart))
    wx.setStorageSync('headPortrait', headPortraitList)
    // console.log(list)
  },
  collectionTapchange(e){
    let list = this.data.headPortraitList;
    let listshorthand = this.data.headPortraitshorthandList;
    console.log(e.currentTarget.dataset.index);
    listshorthand.splice(e.currentTarget.dataset.index,1);
    // console.log(listshorthand);
    // console.log(e.currentTarget.dataset.index);
    list[e.currentTarget.dataset.id].collectionactive = true
    if(!(list[e.currentTarget.dataset.id].collectionactive)){
      this.setData({
        // likeactive : false,
        // headPortraitList : list
      })
    }
    else{
      this.setData({
        // likeactive : true,
        headPortraitshorthandList:listshorthand,
        headPortraitList : list
      })
    }
  
    this.saveheadPortraitToStorage(this.data.headPortraitList)

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    if (wx.getStorageSync('headPortrait')) {
      let list = wx.getStorageSync('headPortrait');
      let listshorthand = list.filter(item => !(item.collectionactive));
      this.setData({
        // likeactive : true,
        headPortraitshorthandList:listshorthand,
        headPortraitList : list
      })
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})